package org.b3log.symphony.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 类HtmlUtil的实现描述：TODO
 *
 * @author Gai 2019/10/19 22:28
 */
public class HtmlUtil {
    public static String removeHtmlTag(String htmlContent) {
        if (htmlContent != null && htmlContent.length() > 0) {
            //去除html标签
            htmlContent = htmlContent.replaceAll("\\s*", ""); //去除空格
            String regEx_html = "<[^>]+>";                      //HTML标签正则表达式
            Pattern pattern = Pattern.compile(regEx_html);
            Matcher matcher = pattern.matcher(htmlContent);
            while (matcher.find()) {
                htmlContent = htmlContent.replace(matcher.group(), "");
            }
            return htmlContent.replaceAll("&nbsp;", "");
        } else {
            return "";
        }
    }
}
